<?php
/**
 * 点赞和关注接口
 */
require_once "login_filter.php";
$my_uuid=$Auth['uuid'];
use app\cls\tom\Response;
use app\cls\tom\SysResource;
if($_REQUEST['type']==0){
    //这是点赞
    if(empty($_REQUEST['video_uuid']) || empty($_REQUEST['uuid'])){
        Response::output(-1,"参数错误fa");
    }
    $type="fabulous";
}else if($_REQUEST['type']==1){
    //这是关注
    if(empty($_REQUEST['uuid'])){
        Response::output(-1,"参数错误fo");
    }
    $type="follow";
}else{
    Response::output(-1,"参数错误1");
}




$data['my_uuid']=$my_uuid;
if(!empty($_REQUEST['video_uuid'])){
    $data['video_uuid']=$_REQUEST['video_uuid'];
}
if(!empty($_REQUEST['uuid'])){
    $data['other_uuid']=$_REQUEST['uuid'];
}
if(!empty($_REQUEST['select_id'])){
    $data['other_id']=$_REQUEST['select_id'];
}

//实例化redis
$redis = SysResource::getRedis();
$suffix=rand(1,5);
$uid=sprintf("%d",crc32($data['my_uuid']));//自己的uuid
$oid=sprintf("%d",crc32($data['other_uuid']));//他人的uuid
$key = REDIS_PREFIX."{$type}_".$suffix;
if($_REQUEST['type']==0){
    $key1=REDIS_PREFIX."{$type}_".$uid;
}else if($_REQUEST['type']==1){
    $key1=REDIS_PREFIX."{$type}_".$uid;//这是我关注的
    $key11=REDIS_PREFIX."is_{$type}_".$oid;//这是我被关注的
}else{
    Response::output(-1,"参数错误2");
}
//1.先去取redis里的信息，判断用户是否存了信息
$da1=$redis->hGet($key1,$uid);
$dad1=json_decode($da1,true);
$arr=[];
//点赞存的是视频的video_uuid,关注存的是用户的uuid
if(empty($dad1)){
  //为空，第一次存
    if($_REQUEST['type']==0){
//        $arr[]=date("Y-m-d H:i:s",time());
//        $redis->hset($key1,$data['video_uuid'],json_encode($arr));
        $time=date("Y-m-d H:i:s",time());
        $redis->hset($key1,$data['video_uuid'],$time);
    }else if($_REQUEST['type']==1){
//        $arr[]=date("Y-m-d H:i:s",time());
//        $redis->hset($key1,$data['other_uuid'],json_encode($arr));
//        $redis->hset($key11,$data['my_uuid'],json_encode($arr));
        $time=date("Y-m-d H:i:s",time());
        $redis->hset($key1,$data['other_uuid'],$time);
        $redis->hset($key11,$data['my_uuid'],$time);
    }
}else{
    //不为空
    if($_REQUEST['type']==0){
//        $dad1[]=date("Y-m-d H:i:s",time());
//        $redis->hset($key1,$data['video_uuid'],json_encode($dad1));
        $time=date("Y-m-d H:i:s",time());
        $redis->hset($key1,$data['video_uuid'],$time);
    }else if($_REQUEST['type']==1){
//        $dad1[]=date("Y-m-d H:i:s",time());
//        $redis->hset($key1,$data['other_uuid'],json_encode($dad1));
//        $redis->hset($key11,$data['my_uuid'],json_encode($dad1));
        $time=date("Y-m-d H:i:s",time());
        $redis->hset($key1,$data['other_uuid'],$time);
        $redis->hset($key11,$data['my_uuid'],$time);
    }

}
//2.再把数据入队列
$redis->lPush($key,json_encode($data));
Response::output(0,"添加成功",$type."_".$suffix);


